<?php
        require_once('paths.inc');
        require_once('page.inc');
        require_once('utils.inc');
        require_once(INCLUDE_PATH.'constants.inc');
        require_once(DB_PATH.'db.inc');    
        
        session_start();
        select_language();
        
        $id_adresa = $_GET['id_adresa'];
        $id_comanda = $_GET['id_comanda'];
        $tip_adresa = $_GET['tip_adresa'];
        $id_lista = $_GET['id_lista'];
        
        $db = db_connect();
        try {
            $comanda = Comanda::queryLoadById($db, $id_comanda, $_SESSION['client_logat']->id_client);
            
            if ($comanda->id_contact_sol != null && $comanda->id_contact_sol != 0)
                $contact_sol = Contact::queryLoadContact($db, $comanda->id_contact_sol);
                
            if ($comanda->id_contact_exec != null && $comanda->id_contact_exec != 0)
                $contact_exec = Contact::queryLoadContact($db, $comanda->id_contact_exec);
                
            $firma1 = Firma::queryLoadById($db, $comanda->id_firma_sol, $_SESSION['client_logat']->id_client);
            $firma2 = Firma::queryLoadById($db, $comanda->id_firma_exec, $_SESSION['client_logat']->id_client);
            
            $adrese = $comanda->adrese_incarcare;
            $text = LANG_Confirma_incarcarea;
            $help_text = LANG_EXTRA_MODAL_CONFIRM_INCARCARE;
            
            if ($tip_adresa == CT_ADRESA_COMANDA_DESCARCARE) {
                $adrese = $comanda->adrese_descarcare;
                $text = LANG_Confirma_descarcarea;
                $help_text = LANG_EXTRA_MODAL_CONFIRM_DESCARCARE;
            }

            foreach($adrese as $adr)
                if ($adr->id_adresa == $id_adresa) {
                    $adresa = $adr;
                    break;
                }
        }
        catch (Exception $e) {
            
        }
        
        echo "<div align=\"center\">";
            echo '<table align="center" cellpadding="3" cellspacing="0" border="0" id="wrapper2">';
                echo "<thead>";
                    echo "<tr>";
                        echo "<th colspan=\"4\">";
                            echo LANG_Detalii_Confirma;
                        echo "</th>";
                    echo "</tr>";                
                echo "</thead>";
                echo '<tr class="capTabel">';
                    echo '<td id="td_cont" align="center" colspan="2"><b>' . LANG_Date_firma .' '. $firma1->nume . '</b></td>';
                    echo '<td id="td_cont" align="center" colspan="2"><b>' . LANG_Date_firma .' '. $firma2->nume . '</b></td>';
                echo '</tr>';
                echo '<tr class="capTabel">';
                    echo '<td id="td_cont" align="left">' . LANG_TEL_FIX . '</td>';
                    echo '<td id="td_cont" align="left">' . $firma1->tel_fix . '</td>';
                    echo '<td id="td_cont" align="left">' . LANG_TEL_FIX . '</td>';
                    echo '<td id="td_cont" align="left">' . $firma2->tel_fix . '</td>';
                echo '</td></tr>';
                echo '<tr class="capTabel">';
                    echo '<td id="td_cont" align="left">' . LANG_TEL_FAX . '</td>';
                    echo '<td id="td_cont" align="left">' . $firma1->tel_fax . '</td>';
                    echo '<td id="td_cont" align="left">' . LANG_TEL_FAX . '</td>';
                    echo '<td id="td_cont" align="left">' . $firma2->tel_fax . '</td>';
                echo '</td></tr>';
                echo '<tr class="capTabel">';
                    echo '<td id="td_cont" align="left">' . LANG_TEL_MOBIL . '</td>';
                    echo '<td id="td_cont" align="left">' . $firma1->tel_mobil . '</td>';
                    echo '<td id="td_cont" align="left">' . LANG_TEL_MOBIL . '</td>';
                    echo '<td id="td_cont" align="left">' . $firma2->tel_mobil . '</td>';
                echo '</td></tr>';
                
                if ($contact_sol != null && $contact_exec != null) {
                    echo '<tr class="capTabel">';
                        if ($contact_sol != null) {
                            echo '<td id="td_cont" align="center" colspan="2"><b>' . $contact_sol->nume . '</b>';
                            echo '<br />' . LANG_TEL_FIX . ': ' . $contact_sol->tel_fix;
                            echo '<br />' . LANG_TEL_FAX . ': ' . $contact_sol->tel_fax;
                            echo '<br />' . LANG_TEL_MOBIL . ': ' . $contact_sol->tel_mobil;
                            echo '</td>';
                        }
                        else
                            echo '<td colspan="2"></td>';
                        if ($contact_exec != null) {
                            echo '<td id="td_cont" align="center" colspan="2"><b>' . $contact_exec->nume . '</b>';
                            echo '<br />' . LANG_TEL_FIX . ': ' . $contact_exec->tel_fix;
                            echo '<br />' . LANG_TEL_FAX . ': ' . $contact_exec->tel_fax;
                            echo '<br />' . LANG_TEL_MOBIL . ': ' . $contact_exec->tel_mobil;
                            echo '</td>';
                        }
                        else
                            echo '<td colspan="2"></td>';
                    echo '</td></tr>';
                }
                echo '<tr class="capTabel">';
                    echo '<td id="td_cont" align="center" colspan="4"><b>' . LANG_Date_sofer . '</b></td>';
                echo '</tr>';
                echo '<tr class="capTabel">';
                    echo '<td id="td_cont" align="left">' . LANG_Nume_sofer . '</td>';
                    echo '<td id="td_cont" align="left">' . $comanda->nume_sofer . '</td>';
                    echo '<td id="td_cont" align="left">' . LANG_tel_sofer . '</td>';
                    echo '<td id="td_cont" align="left">' . $comanda->tel_sofer . '</td>';
                echo '</td></tr>';
                echo '<tr class="capTabel">';
                    echo '<td></td><td id="td_data" align="right"><b>' . LANG_Data_si_ora_programata . '</b></td>';
                    echo '<td>'.$adresa->data.'</td><td></td>';
                echo '</td></tr>';
                echo '<tr class="capTabel">';
                    echo '<td></td><td id="td_data_efectiva" align="right"><b>' . LANG_Data_si_ora . CT_OBLIGATORIU . '</b></td>';
                    echo '<td>'.render_date_field_with_ora_button($adresa->data_efectiva, 'data_efectiva', 'DHTMLSuite_modalBox_contentDiv').'</td><td></td>';
                echo '</td></tr>';
                
                echo '<tr class="capTabel">';
                    echo "<td colspan=\"4\" align=\"center\">";
                        echo '<input type="button" name="date_confirm" id="date_confirm" value="' . $text . '"' . "onclick=\"javascript: date_confirm('" . $id_adresa ."','" . $id_comanda  ."','" . $id_lista ."','" . $tip_adresa . "');\" />&nbsp;&nbsp;";
                        echo '<input type="button" name="cancel" value="'.LANG_CANCEL.'" onclick="javascript: closeMessage();" />';                        
                    echo "</td>";
                echo '</tr>';
                echo output_extra_text_modal($help_text, 4);
            echo '</table>';    
        echo "</div>";        
        flush();
?>